Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR modifies the DynamicClassBridge class to dynamically retrieve the indexer name from the System.Linq.Dynamic.Core.DynamicClass type instead of hardcoding it as "Item". This change makes the code more flexible and adaptable to potential variations in the DynamicClass implementation.
Key Changes
- Replaced hardcoded indexer method lookup with dynamic retrieval based on a static field
- Added reflection logic to read the
IndexerNamefield from the DynamicClass type - Included fallback to "Item" if the field is not found or null
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| var indexerNameField = CLASS_TYPE.GetField("IndexerName", BindingFlags.NonPublic | BindingFlags.Static); | ||
| var indexerName = indexerNameField?.GetValue(null) as string ?? "Item"; | ||
| INDEXER_METHOD = CLASS_TYPE.GetMethod("get_" + indexerName); |
There was a problem hiding this comment.
The GetMethod call on line 29 can return null if the method is not found. This would leave INDEXER_METHOD as null, causing a NullReferenceException when GetMember is invoked later (line 43). Consider adding null-checking and throwing a descriptive exception if the method cannot be found, similar to how other reflection calls are handled in this constructor.
| INDEXER_METHOD = CLASS_TYPE.GetMethod("get_" + indexerName); | |
| INDEXER_METHOD = CLASS_TYPE.GetMethod("get_" + indexerName); | |
| if (INDEXER_METHOD == null) | |
| throw new Exception($"Could not find indexer method 'get_{indexerName}' on type '{CLASS_TYPE.FullName}'."); |
Caused by / v1.6.8: